<?php
class latestInfoWidget extends CWidget
{
	public $bloglist = array();
	public $htmlOptions = array();
	public $limit = 5;
	
	public $timeFormat = "Y/m/d";
	
	public $cname;
	public $length = 15;
	
	
	public function run()
	{
	
		
        $criteria = new CDbCriteria(array(
            'condition'=>'arc_state = '.Article::STATUS_PUBLISHED,
            'order'=>'arc_id DESC',
        	'limit'=>$this->limit
        ));
        
        if($this->cname)
        {	
        	$id = $this->cname;
        	
        	$categories = Category::model()->findAll('cate_type = :cate_type',array(':cate_type'=>$id));
        	
        	$ids = array();
        	
        	$i = 1;
        	
        	foreach ($categories as $category)
        	{
        		$id = $category->cate_id;
        		
        		if($i == 1){
        			$condition = "arc_cid like '%,{$id}' OR arc_cid like '%,{$id},' OR arc_cid like '%{$id},' OR arc_cid = '{$id}'";
        		}
        		else 
        		{
        			$condition .= " OR arc_cid like '%,{$id}' OR arc_cid like '%,{$id},' OR arc_cid like '%{$id},' OR arc_cid = '{$id}'";
        		}
        		
        			
//        		echo $condition;
        		
        		$i++;
        	}
        	
        	
        	$criteria->addCondition($condition);
        }
		
//		if($this->cname == '')
//			$criteria->addSearchCondition('arc_cid',$this->cname);
        
        $list = Article::model()->findAll($criteria);

			
//		UtilTools::dump($criteria);
//		die();
	
//		$list = Article::model()->findAll("arc_state = :arc_state AND arc_cid LIKE '%:arc_cid%' ORDER BY arc_cid DESC LIMIT :limit",array(
//			':arc_state'=>Article::STATUS_PUBLISHED,
//			':limit'=>5,
//			':arc_cid'=>$this->cname
//		));

		$this->render('info',array(
			'list'=>$list
		));
	}
}
?>